<!DOCTYPE html>
<html>
<head>
<title>I LOVE U</title>
<style>
body {
  margin: 0;
  overflow: hidden;
  background-color: black;
}

#heart-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.heart {
  position: absolute;
  width: 30px;
  height: 30px;
  background-color: pink;
  transform: rotate(-45deg);
  border-radius: 50%;
  animation: flutter 4s linear infinite, glow 1.5s alternate infinite;
  will-change: transform, opacity; /* 建议: 配合JS里的heartCount一起使用，如果性能还是有问题再考虑这个 */
}

@keyframes flutter {
  0% {
    transform: translateY(0) translateX(0) rotate(-45deg);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(calc(100vh + 30px)) translateX(var(--random-x)) rotate(calc(360deg * var(--random-rotate) - 45deg));
    opacity: 0;
  }
}

@keyframes glow {
  0% {
    box-shadow: 0 0 5px pink;
  }
  100% {
    box-shadow: 0 0 20px lightpink;
  }
}

#love-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 5em;
  font-family: sans-serif;
  color: lightblue;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  animation: fadeInOut 4s ease-in-out infinite, textGlow 1.5s alternate infinite;
  opacity: 0.8; /* 设置初始不透明度，避免完全透明 */
  will-change: opacity, transform; /* 建议: 如果动效复杂，可以考虑添加 */
}

@keyframes fadeInOut {
    0%, 100% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05); /* 微微放大 */
    }
}

@keyframes textGlow {
  0% {
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  }
  100% {
    text-shadow: 2px 2px 10px rgba(0, 173, 216, 0.8);
  }
}

</style>
</head>
<body>

<div id="heart-container"></div>
<div id="love-text">I LOVE U</div>

<script>
const heartContainer = document.getElementById('heart-container');
const targetHeartCount = 100; // 目标心形数量
let heartCount = 0; // 当前心形数量

function createHeart() {
  const heart = document.createElement('div');
  heart.className = 'heart';

  const randomX = Math.random() * 100 - 50;
  const randomRotate = Math.random();

  heart.style.setProperty('--random-x', `${randomX}vw`);
  heart.style.setProperty('--random-rotate', randomRotate);

  heart.style.left = `${Math.random() * 100}vw`;
  heart.style.top = `${Math.random() * 100}vh`;

  heartContainer.appendChild(heart);
  heartCount++;

  heart.addEventListener('animationend', () => {
    heart.remove();
    heartCount--;
  });
}

// 初始填充心形
while (heartCount < targetHeartCount) {
    createHeart();
}

// 定时检查心形数量，并进行补充
setInterval(() => {
    while (heartCount < targetHeartCount) {
        createHeart();
    }
}, 50); // 每 50 毫秒检查一次
</script>

</body>
</html>